//
//					Button.h
//

#ifndef __NEWA_BUTTON_H
#define __NEWA_BUTTON_H

#pragma message( "INCLUDING FILE: " __FILE__ )

#include "Base.h"
#include "Events.h"
#include "Disposal.h"
#include "WidgetStyle.h"
#include "Widget.h"
#include "WidgetElement.h"

namespace newa
{
	class Button : public Widget
	{
	public:
		EventTraits< EVCLICK >::HandlerFtor OnClick;

		Button()
		{
			m_element = WidgetElement::create( _T("button") );
			m_element->OnPaint = EventTraits< EVPAINT >::HandlerFtor( this, &Button::paint );
			m_element->OnClick = EventTraits< EVCLICK >::HandlerFtor( this, &Button::onClick );
		}

		WidgetElementRef site()
		{
			return m_element;
		}

		WidgetElementRef elem()
		{
			return m_element;
		}

		void rect( const Rect& r )
		{
			m_element->rect( r );
		}

		Rect rect() const
		{
			return m_element->rect();
		}

	protected:
		virtual void onClick()
		{
			if( OnClick )
				OnClick();
		}

		virtual void paint( PixBuf * pb )
		{
			styleMan().style().paintButton( *this, *pb );
		}

	private:
		WidgetElementRef m_element;
	};

	class ToggleButton : public Button
	{
	public:
		ToggleButton()
			: m_toggled( false )
		{
		}

		bool toggled() const
		{
			return m_toggled;
		}

	protected:

		virtual void onClick()
		{
			Button::onClick();
			m_toggled = ! m_toggled;
		}

		virtual void paint( PixBuf * pb )
		{
			styleMan().style().paintToggleButton( *this, *pb );
		}
	private:
		bool m_toggled;
	};

	class CheckBox : public ToggleButton
	{
	protected:
		virtual void paint( PixBuf * pb )
		{
			styleMan().style().paintCheckBox( *this, *pb );
		}
	};

}

#endif
